package main;

import java.io.FileNotFoundException;
import java.io.InputStream;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.advanced.AdvancedPlayer;

public class SoundButton extends MediaButton implements Mediafile {
	
	private final String mediaFolder = "/media/";
	
	private String filename;
	
	public SoundButton(String soundfile, String name) {
		this(soundfile, name, "");
	}
	
	public SoundButton(String soundfile, String name, String tooltip) {
		this.setText(name);
		if (tooltip != "") {
			this.setToolTipText(tooltip);
		}
		this.filename = soundfile;
		this.addActionListener(this);
	}
	
	public void play() throws FileNotFoundException, JavaLayerException {
		String pathForInputStream = this.mediaFolder + this.filename;
		InputStream is = getClass().getResourceAsStream(pathForInputStream);
		if (is == null) {
			throw new RuntimeException("Fehler: InputStream konnte nicht erstellt werden ("
					+ pathForInputStream + ")");
		}
		new AdvancedPlayer(is).play();
	}
}